from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC








def cancel_net(driver):
    # 访问网页
    driver.get("http://1.1.1.3/ac_portal/default/pc.html?type=logout&username=10.73.19.54")
    # 等待按钮元素加载完成
    button = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.CSS_SELECTOR, "#logout_submitBtn"))
    )
    # 点击按钮
    button.click()


def test_baidu(driver):
    # 访问百度首页
    driver.get("https://www.baidu.com")
    # 等待搜索框元素加载完成
    search_box = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "kw"))
    )
    # 如果能找到搜索框元素，则表示能访问百度首页
    print("能访问百度首页")


# 创建一个 WebDriver 实例
driver = webdriver.Chrome()
try:
    # cancel_net(driver)
    test_baidu(driver)
except Exception as e:
    print("无法访问百度首页：", str(e))
finally:
    # 关闭浏览器
    driver.quit()
